package com.boxin.ims.modules.sys.utils;

import java.security.MessageDigest;

import com.thinkgem.jeesite.common.security.Digests;
import com.thinkgem.jeesite.common.utils.Encodes;

import sun.misc.BASE64Encoder;
/**
 * @author Jakemanse
 * @date 2014-2-27
 * @function <p> </p>
 */
public class EncryptUtils {
	
	
	public static final String HASH_ALGORITHM = "SHA-1";
	public static final int HASH_INTERATIONS = 1024;
	public static final int SALT_SIZE = 8;
	
	
	
	public static String MD5EncodeString(String str){
		try {
			MessageDigest md5=MessageDigest.getInstance("MD5"); 
			BASE64Encoder base64en = new BASE64Encoder(); 
			String newstr=base64en.encode(md5.digest(str.getBytes("UTF-8"))); 
			
			
			return newstr;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	
	/**
	 * 验证密码
	 * @param plainPassword 明文密码
	 * @param password 密文密码
	 * @return 验证成功返回true
	 */
	public static boolean validatePassword(String plainPassword, String password) {
//		byte[] salt = Encodes.decodeHex(password.substring(0,16));
//		byte[] hashPassword = Digests.sha1(plainPassword.getBytes(), salt, HASH_INTERATIONS);
//		return password.equals(Encodes.encodeHex(salt)+Encodes.encodeHex(hashPassword));
		return password.equals(MD5EncodeString(plainPassword));
	}
	

}
